var expireTime = null,startTime = null,xmlHttp=null, start_price =null; var visitHistory, line_id;
function DoSubmit(formObj){
	
	var formInputObjArray = formObj.getElementsByTagName("input");
	
	var thisTimeValue = "",AdultNumValue ="", KidNumValue = "";
	for(var i=0; i<formInputObjArray.length; i++){
		switch(formInputObjArray[i].name){
			case "thisTime":
				thisTimeValue = formInputObjArray[i].value;
				break;
			case "AdultNum":
				AdultNumValue = formInputObjArray[i].value;
				break;
			case "KidNum":
				KidNumValue = formInputObjArray[i].value;
				break;
			default:
				break;
		}
	}
	
	var formSelectObjArray = formObj.getElementsByTagName("select");
	for(var i=0; i<formSelectObjArray.length; i++){
		switch(formSelectObjArray[i].name){
			case "thisTime":
				thisTimeValue = formSelectObjArray[i].value;
				break;
			case "AdultNum":
				AdultNumValue = formSelectObjArray[i].value;
				break;
			case "KidNum":
				KidNumValue = formSelectObjArray[i].value;
				break;
			default:
				break;
		}
	}	

	if(thisTimeValue=="" || thisTimeValue=="请输入日期"  ){
		alert("请选择参团时间");
		return false;
	}
		
	if(AdultNumValue=="" || isNaN(AdultNumValue) || AdultNumValue<1){
		alert("请输入成人参团人数(数字)");
		return false;
	}
	
	if(KidNumValue=="" || isNaN(KidNumValue) || KidNumValue<0 ){
		alert("请输入儿童参团人数(数字)");
		return false;
	}		
		
	return true;
}


OnSelectDate = function(){
	document.getElementById("thisTimeMsg").style.color='#333333';
	document.getElementById("AdultNum").focus();

	var GroupDate = document.getElementById("thisTime").value;
	var Year = parseInt(GroupDate.substr(0,4),10);
	var Month = parseInt(GroupDate.substr(5,2),10);
	var Day = parseInt(GroupDate.substr(8,2),10);
	var temp = GetPlan(CaculateDay(Year,Month - 1,Day));
	
	
	if(temp==null)
		return;
	document.getElementById("price").innerHTML='<br />　'
		+ '<font style="font-family:宋体">*</font><strong>'
		+ GroupDate
		+'预定价格为 </strong>成人价格 ￥<font color="#FF3300">'
		+ temp.AdultPrice
		+ '</font>　儿童价格 ￥<font color="#FF3300">'
		+ temp.KidPrice
		+'</font>'
		+ '';	
}

function goUrl(){
	var tempObj =document.getElementById('lineId')
	if(!tempObj) return;
	temp = tempObj.value;
	if(temp!="") {
		switch(temp.substring(0,1)){
			case "p":
			case "P":
				window.location = '/vacation/'+temp.substring(1)+'.html'; 
				break;
			default:
				window.location = '/line/'+temp+'.html'; 
				break;
		}
	}
	return false;	
}

function showDisplay(){
	tempObj = document.getElementById("doDisplay").getElementsByTagName("TR");
	for(var i=0; i<tempObj.length; i++)
	{
		tempObj[i].style.display="";
	}
	document.getElementById("doDisplayNone").style.display="none";
	
}
function goDown(length){
	var where = document.getElementById('doDisplay').scrollTop + (length);
	if(where<0) 
		where=1;
	document.getElementById('doDisplay').scrollTop = where;


	return false;
}


function changeAdultNum(num){
	if(isNaN(num)){
		var s = '<input type="text" value="" name="AdultNum" id="AdultNum" style="width:45px;">';
		if(document.getElementById('AdultNumHtmlFir'))
			document.getElementById('AdultNumHtmlFir').innerHTML = s;
		if(document.getElementById('AdultNumHtmlSec'))
			document.getElementById('AdultNumHtmlSec').innerHTML = s;
	}
	return;
}

function changeKidNum(num){
	if(isNaN(num)){
		var s = '<input type="text" value="" name="KidNum" id="KidNum" style="width:45px;">';
		if(document.getElementById('AdultNumHtmlFir'))
			document.getElementById('KidNumHtmlFir').innerHTML = s;
		if(document.getElementById('AdultNumHtmlSec'))
			document.getElementById('KidNumHtmlSec').innerHTML = s;
	}
	return;
}
changeRoomNum = function(num){
	if(isNaN(num)){
		var s = '<input type="text" value="" name="room_num" id="room_num" style="width:45px;">';
		if(document.getElementById('RoomNumHtmlSec'))
			document.getElementById('RoomNumHtmlSec').innerHTML = s;
	}
	return;
}


function newSelectStartDate(date)
{
	var tempObjArray = document.getElementsByName('thisTime');
	for(var i=0; i<tempObjArray.length; i++ ){
		tempObjArray[i].value = date;
	}
	return;
}

function SelectStartDate(date)
{
	document.getElementById('thisTime').value=date;; 
	document.getElementById('AdultNum').select();
	OnSelectDate();
}

//显示访问记录
var newShowContent = "";
function SetVisitHistory(line_name,type,contentType){
	var showString = "", writeCookie = "", cookieName = "";
	switch(type){
		case "2":
			cookieName = "vacationVisitHistory";
			break;
		case "3":
			cookieName = "sanyaHotelVisitHistory";
			break;
		default:
			cookieName = "lineVisitHistory";
			break;
	}	

	var visitCookieSting = GetCookieData(cookieName);
	var tempArray_1 = visitCookieSting.split("@@");
	
	var visitArray = [];
	var index = 0;

	for(var i=0; i<tempArray_1.length; i++){
		var tempArray_2 = tempArray_1[i].split(",");
		if(tempArray_2.length<3) continue;
		if(isNaN(tempArray_2[0]) || tempArray_2[0]=="") continue;
		if( tempArray_2[0]*1 == line_id*1 && tempArray_2[2]*1 ==type*1 ) continue;
		
		visitArray[index] = {
			"line_id":tempArray_2[0],
			"line_name":(tempArray_2[1]),
			"line_type":tempArray_2[2]
		};
		index++;
		if(index>5){
			break;
		}
	}
	
	writeCookie += (line_id + ',' + escape(line_name) + ","+type);
	for(var i=0; i<visitArray.length; i++ ){
		writeCookie += "@@" + visitArray[i]["line_id"] + ',' + escape(visitArray[i]["line_name"]) + ','+visitArray[i]["line_type"];
		showString += '<div id="zuij">';
		switch(visitArray[i]["line_type"]){
			case "2":
				showTempString = '<a href="/vacation/'+visitArray[i]["line_id"]+'.html">'+visitArray[i]["line_name"]+'</a>';
				break;
			case "3":
				showTempString = '<a href="http://sanya.landtu.com/'+visitArray[i]["line_id"]+'.html">'+visitArray[i]["line_name"]+'</a>';
				break;
			default:
				showTempString = '<a href="/line/'+visitArray[i]["line_id"]+'.html">'+visitArray[i]["line_name"]+'</a>';
				break;
		}
		showString += showTempString;
		showString += '</div>';
		
		newShowContent += '<li';
		if(i==0){
			newShowContent += ' style="border-top:none;"';
		}else if(i==visitArray.length-1){
			newShowContent += ' style="border-bottom:none;"';
		}
		newShowContent += '>';
		newShowContent += showTempString+'</li>';
	}
	if(newShowContent!="")
		newShowContent = '<div id="tlr_title"><h3>最近浏览过的线路</h3></div><ul id="tlr_list">' + newShowContent + '</ul>';
	
	if(contentType!=1){
		HtmlInitFuc(function(){
			var visitHistory = document.getElementById('visitHistory');
			if(!visitHistory) return;
			visitHistory.style.textAlign = "left";
			visitHistory.style.padding = "0";
			visitHistory.innerHTML = showString;
			return;
		});
	}

	var Days = 365; //此 cookie 将被保存 90 天
    var exp  = new Date();    //new Date("December 31, 9998");
    exp.setTime(exp.getTime() + Days*24*60*60*1000);	
	document.cookie = cookieName+"="+(writeCookie)+";expire="+ exp.toGMTString()+";path=/;";
	return;
}

writeVisitContent = function(){
	document.write(newShowContent);
	return;
}


//新的图片显示效果
ImgShowAction = function(){
	if(LinePhotoString.length==0)
		return;
	
	var contentString = "";
	for(var i=0; i<LinePhotoString.length; i++){
		contentString += '<img src="'+LinePhotoString[i][0]+'" width="51" height="36" style="cursor:pointer" onmouseover="bigImgShow(this,'+i+')" onmouseout="hidBigShow();"  onclick="document.getElementById(\'showPageImg\').src=\''+LinePhotoString[i][1]+'\'" />';
	}
	document.write(contentString);
	return;
}

bigImgShow = function(obj,curPointIndex){
	if(curPointIndex>=LinePhotoString.length)
		return;
	
	//显示层
	var showObjDiv = document.getElementById( "imgBigDiv" );
	if(!showObjDiv){
		showObjDiv = document.createElement('DIV');
		showObjDiv.style.display='none';
		showObjDiv.style.position='absolute';
		showObjDiv.id='imgBigDiv';
		var bs = document.getElementsByTagName('BODY');
		bs[0].appendChild(showObjDiv);
	}
	
	
	//显示内容
	var tempString = "", addWidth = 8;
	tempString = '<iframe MARGINWIDTH=0 MARGINHEIGHT=0 HSPACE=0 VSPACE=0 FRAMEBORDER=0 SCROLLING=no ';
	if(LinePhotoString[curPointIndex][2]>300){
		tempString +=' width="'+(300+addWidth)+'"';
		tempString +=' height="'+(300*LinePhotoString[curPointIndex][3]/LinePhotoString[curPointIndex][2]*1+addWidth)+'"';
	}else{
		tempString +=' width="'+(LinePhotoString[curPointIndex][2]*1+addWidth)+'"';
		tempString +=' height="'+(LinePhotoString[curPointIndex][3]*1+addWidth)+'"';
	}
	tempString +='  id="ShowBigImgIframe" ></iframe>';
	showObjDiv.innerHTML = tempString;
	
	var Browser = { 
		'isIE' : (navigator.userAgent.indexOf('MSIE') >= 0) && (navigator.userAgent.indexOf('Opera') < 0), 
		'isFirefox' : navigator.userAgent.indexOf('Firefox') >= 0, 
		'isOpera' : navigator.userAgent.indexOf('Opera') >= 0 
	}; 
	
	var frame;
	if(Browser.isIE){
		frame = document.frames("ShowBigImgIframe").document;
	}else{
		frame = document.getElementById('ShowBigImgIframe').contentDocument;
	}
	
	var showObjDivInnerHTML = '<div style="border:1px solid #D8E7FE;"><img style="padding:3px; background:#fff;" src="'+LinePhotoString[curPointIndex][1]+'" ';
	if(LinePhotoString[curPointIndex][2]>300){
		showObjDivInnerHTML += ' width="300"';
		showObjDivInnerHTML += ' height="'+300*LinePhotoString[curPointIndex][3]/LinePhotoString[curPointIndex][2]*1+'"';
	}else{
		showObjDivInnerHTML += ' width="'+LinePhotoString[curPointIndex][2]*1+'"';
		showObjDivInnerHTML += ' height="'+LinePhotoString[curPointIndex][3]*1+'"';
	}
	showObjDivInnerHTML += '/></div>';
	
	tempString  = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
	tempString += '<html xmlns="http://www.w3.org/1999/xhtml">';
	tempString += '<head>';
	tempString += '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
	tempString += '<title></title>';
	tempString += '<style>';
	tempString += '*{ margin:0; padding:0;}';
	tempString += '</style>';
	tempString += '</head>';
	tempString += '<body>';
	tempString += showObjDivInnerHTML;
	tempString += '</body>';
	tempString += '</html>';	
	
	frame.open();
	frame.write(tempString);
	frame.close();
	
	
	//定位
	var OBTop=0,OBLeft=0,OBWidth=0,OBHeight=0;
	var oCurrentNode = obj;
	while(oCurrentNode != null && oCurrentNode.tagName != "BODY"){
		OBTop += oCurrentNode.offsetTop;
		OBLeft += oCurrentNode.offsetLeft;
		oCurrentNode = oCurrentNode.offsetParent;
	}
	OBTop += document.getElementsByTagName('BODY')[0].offsetTop 
	OBLeft += document.getElementsByTagName('BODY')[0].offsetLeft 

	showObjDiv.style.top = (OBTop + 4 + obj.offsetHeight + "px");
	showObjDiv.style.left = (OBLeft  + 0 + "px");

	if( (300*LinePhotoString[curPointIndex][3]/LinePhotoString[curPointIndex][2]+OBTop*1)*1 >(document.documentElement.clientHeight*1+document.documentElement.scrollTop)*1){
		showObjDiv.style.top = (OBTop - 0 + "px");
		showObjDiv.style.left = (OBLeft  + obj.offsetWidth + 4 + "px");
	}

	//显示层
	showObjDiv.style.display='';
	return;
}


hidBigShow = function(){
	var showObjDiv = document.getElementById( "imgBigDiv" );
	if(!showObjDiv)
		return;
	showObjDiv.style.display='none';
	return;
}



//线路详细页面的幻灯片
whereHotImgPage = 1;
nextEnd = false;
preEnd = false;
hotImgOnePageNum = 5;
hotImgTotalPage = 0;
hotImgCurPage = 1;
hotImgWhere = 0;
var imgListObj = [];


showHotImg = function(){
	
	if(LinePhotoString.length==0)
		return;
	HtmlInitFuc(function(){
		for(var i=0; i<LinePhotoString.length; i++){
			imgListObj[i] = new Image();
			imgListObj[i].src = LinePhotoString[0][1];	
		}
		return;
	});	
	hotImgTotalPage = parseInt(LinePhotoString.length/hotImgOnePageNum,10);
	if(hotImgTotalPage*hotImgOnePageNum<LinePhotoString.length) hotImgTotalPage = hotImgTotalPage+1;
	
	var writeHtmlSting = "";
	writeHtmlSting += '<div id="tlpic">';
	writeHtmlSting += '<img src="';
	writeHtmlSting += LinePhotoString[0][1];
	writeHtmlSting += '" style="filter:revealTrans(Transition=1,Duration=0.9); cursor:pointer;" onclick="goImgNext();" />';
	writeHtmlSting += '</div>';
	writeHtmlSting += '<div id="tlpictol">第 <span id="curPage">'+hotImgCurPage+'</span> 张  共 '+LinePhotoString.length+' 张</div>';
	writeHtmlSting += '<div id="tlpicdiv">';
	
	writeHtmlSting += '<div class="tlpiculdiv1" id="goPicPre"><a href="#" onclick="goPre();return false;"><img src="../images/img/tlpic_ls.jpg" /></a></div>';
	
	if(LinePhotoString.length>5)
		writeHtmlSting += '<div class="tlpiculdiv2" id="goPicSec"><a href="#" onclick="goNext();return false;"><img src="../images/img/tlpic_r.gif" /></a></div>';
	else
		writeHtmlSting += '<div class="tlpiculdiv2" id="goPicSec"><a href="#" onclick="goNext();return false;"><img src="../images/img/tlpic_rs.jpg" /></a></div>';	
	
	
	writeHtmlSting += '<div style="width:586px; overflow:hidden; white-space:nowrap; margin-left:6px; padding-left:2px;" id="LineShowImgList">';
	writeHtmlSting += '<div style="width:'+(hotImgTotalPage*hotImgOnePageNum*120)+'px; white-space:nowrap;" id="LineShowImgList">';	
	writeHtmlSting += '<ul id="tlpicul">';
	for(var index=0; index<LinePhotoString.length; index++){
		writeHtmlSting += '<li style="cursor:pointer" onclick="selectSmallImg('+index+');"';
		if(index==0)
			writeHtmlSting += ' class="tlpicli"';
		writeHtmlSting += '>';
		writeHtmlSting += '<img src="';
		writeHtmlSting += LinePhotoString[index][0];
		writeHtmlSting += '" />';
		writeHtmlSting += '</li>';
	}

	writeHtmlSting += '</ul>';
	writeHtmlSting += '</div>';
	writeHtmlSting += '</div>';
	
	
	writeHtmlSting += '</div>';
	
	
	/*
	//大图片
	writeHtmlSting += '<div id="tl_pic">';
	writeHtmlSting += '<img src="';
	writeHtmlSting += LinePhotoString[0][1];
	writeHtmlSting += '" width="578" height="385" style="filter:revealTrans(Transition=1,Duration=0.9); cursor:pointer;" onclick="goImgNext();" />';
	writeHtmlSting += '</div>';

	//小图片 tlpic_l.gif tlpic_ls.jpg		tlpic_r.gif tlpic_rs.jpg
	writeHtmlSting += '<div id="tl_pic_list">';
	writeHtmlSting += '<div class="pic_listl" id="goPicPre"><a href="#" onclick="goPre();return false;"><img src="../images/img/tlpic_ls.jpg" /></a></div>';
	
	if(LinePhotoString.length>5)
		writeHtmlSting += '<div class="pic_listr" id="goPicSec"><a href="#" onclick="goNext();return false;"><img src="../images/img/tlpic_r.gif" /></a></div>';
	else
		writeHtmlSting += '<div class="pic_listr" id="goPicSec"><a href="#" onclick="goNext();return false;"><img src="../images/img/tlpic_rs.jpg" /></a></div>';
		
	writeHtmlSting += '<div style="width:578px; overflow:hidden; float:left; white-space:nowrap; margin-left:34px; padding-left:4px;" id="LineShowImgList">';
	writeHtmlSting += '<div style="width:'+(hotImgTotalPage*hotImgOnePageNum*120)+'px; white-space:nowrap;" id="LineShowImgList">';
	writeHtmlSting += '<ul>';
	for(var index=0; index<LinePhotoString.length; index++){
		writeHtmlSting += '<li onclick="selectSmallImg('+index+');"';
		if(index==0)
			writeHtmlSting += ' class="picstop"';
		writeHtmlSting += '>';
		writeHtmlSting += '<img src="';
		writeHtmlSting += LinePhotoString[index][0];
		writeHtmlSting += '" width="107" height="84" />';
		writeHtmlSting += '</li>';
	}
	writeHtmlSting += '</ul>';
	writeHtmlSting += '</div>';
	writeHtmlSting += '</div>';

	writeHtmlSting += '</div>';
	
	*/
	document.write(writeHtmlSting);
	return;
}

selectSmallImg = function(whereIndex){
	var BigImgObj = document.getElementById('tlpic').getElementsByTagName("img")[0];
	var tempLiArray = document.getElementById('tlpicdiv').getElementsByTagName("li"); 

	for(var index=0; index<tempLiArray.length; index++){
		tempLiArray[index].className = "";
	}
	tempLiArray[whereIndex].className = "tlpicli";
	hotImgWhere = whereIndex;
	
	document.getElementById('curPage').innerHTML = hotImgWhere+1;
	
	try{
		BigImgObj.filters.item(0).transition = 12;
		BigImgObj.filters.item(0).Apply();
		BigImgObj.src = LinePhotoString[whereIndex][1]
		BigImgObj.filters.item(0).Play();
	}catch(e){
		BigImgObj.src = LinePhotoString[whereIndex][1]
	}		
	return;
}

goImgNext = function(){
	var tempLiArray = document.getElementById('tlpicdiv').getElementsByTagName("li"); 	
	if( hotImgWhere + 1 <tempLiArray.length )
		hotImgWhere = hotImgWhere + 1;
	else
		return;
		
	selectSmallImg(hotImgWhere);
	if(hotImgWhere+1 > hotImgCurPage * hotImgOnePageNum)
		goNext();
	return;
}

goPre = function(){
	var goPicPreObj = document.getElementById('goPicPre');
	var PicPreImgObj = goPicPreObj.getElementsByTagName("img")[0];
	var goPicSecObj = document.getElementById('goPicSec');
	var PicSecImgObj = goPicSecObj.getElementsByTagName("img")[0];
	
	if(preEnd){
		return;	
	}
	
	hotImgCurPage = hotImgCurPage-1;
	if(hotImgCurPage<=1){
		PicPreImgObj.src = "../images/img/tlpic_ls.jpg";
		hotImgCurPage = 1;
		preEnd = true;
	}else{
		PicPreImgObj.src = "../images/img/tlpic_l.gif";
	}
	
	goHotImgMove(-119*5);
	
	PicSecImgObj.src = "../images/img/tlpic_r.gif";
	nextEnd = false;
	return;
}

goNext = function(){
	var goPicPreObj = document.getElementById('goPicPre');
	var PicPreImgObj = goPicPreObj.getElementsByTagName("img")[0];
	var goPicSecObj = document.getElementById('goPicSec');
	var PicSecImgObj = goPicSecObj.getElementsByTagName("img")[0];
	
	if(LinePhotoString.length<=5){
		PicSecImgObj.src = "../images/img/tlpic_rs.jpg";
		return;
	}
	if(nextEnd){
		return;
	}
	
	hotImgCurPage = hotImgCurPage + 1;
	if(hotImgCurPage>=hotImgTotalPage){
		PicSecImgObj.src = "../images/img/tlpic_rs.jpg";
		nextEnd = true;
	}
	goHotImgMove(119*5);
	
	PicPreImgObj.src = "../images/img/tlpic_l.gif";
	preEnd = false;
	return;
}


function goHotImgMove(length){
	var where = document.getElementById('LineShowImgList').scrollLeft + (length);
	if(where<0) {
		document.getElementById('LineShowImgList').scrollLeft = 0;
		return;
	}
//		document.getElementById('LineShowImgList').scrollLeft = where;
//		return;
	document.getElementById('LineShowImgList').scrollLeft += length - parseInt(length/onceMoveLength,10)*onceMoveLength 
	clearInterval(MyMar);
	runLength += parseInt(length/onceMoveLength,10);
	MyMar=setInterval(autoMoveHotImg,speed);
	//document.getElementById('LineShowImgList').scrollLeft = where;
	return;
}

var speed = 1;
var runLength = 0;
var MyMar;
var onceMoveLength = 40	//一次移动的距离
autoMoveHotImg = function(){
	if(runLength==0){
		clearInterval(MyMar);
		return;
	}
	if(runLength>0){
		document.getElementById('LineShowImgList').scrollLeft+=onceMoveLength;
		runLength-=1;
	}else{
		document.getElementById('LineShowImgList').scrollLeft-=onceMoveLength;
		runLength+=1;
	}	
	return;
}